package com.tools.genxsd.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.tools.genxsd.constant.RegexConstant.*;

/**
 * @author: zhoubin
 * @date: 2022/11/16
 */
public class PatternUtil {

    public static String isSimpleText(String name) {
        Pattern compile = Pattern.compile(SIMPLE_TEXT_REGEX);
        Matcher matcher = compile.matcher(name);
        if (matcher.find()) {
            return matcher.group(1);
        }

        return null;
    }

    public static String isNumberText(String name) {
        Pattern compile = Pattern.compile(NUMERIC_TEXT_REGEX);
        Matcher matcher = compile.matcher(name);
        if (matcher.find()) {
            return matcher.group(1);
        }

        return null;
    }

    public static String splitXsdName(String sheetName) {

        Pattern compile = Pattern.compile(XSD_FILE_NAME_REGEX);
        Matcher matcher = compile.matcher(sheetName);
        if (matcher.find()) {
            return matcher.group(0);
        }

        return null;
    }

    public static boolean isExcel(String fileName) {
        if (fileName.endsWith(".xlsx") || fileName.endsWith(".xls")) {
            return true;
        }

        return false;
    }
}
